﻿
@{
    ViewBag.Title = "新增库位";
}
<form class="layui-form layui-form-pane" lay-filter="">
    <div class="layui-form-item">
        <label class="layui-form-label">所属园区</label>
        <div class="layui-input-inline">
            <select id="ParkID" name="ParkID" lay-filter="ParkID" lay-verify="required">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属仓库</label>
        <div class="layui-input-inline">
            <select id="StorehouseID" name="StorehouseID" lay-verify="required">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库位编号</label>
        <div class="layui-input-inline">
            <input type="text" name="Code" autocomplete="off" class="layui-input" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库位面积</label>
        <div class="layui-input-inline">
            <input type="text" name="Area" autocomplete="off" class="layui-input" lay-verify="number" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库位长度</label>
        <div class="layui-input-inline">
            <input type="text" name="Length" autocomplete="off" class="layui-input" lay-verify="number" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库位宽度</label>
        <div class="layui-input-inline">
            <input type="text" name="Width" autocomplete="off" class="layui-input" lay-verify="number" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库位高度</label>
        <div class="layui-input-inline">
            <input type="text" name="Height" autocomplete="off" class="layui-input" lay-verify="number" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库位描述</label>
        <div class="layui-input-inline">
            <input type="text" name="Description" autocomplete="off" class="layui-input" maxlength="500" />
        </div>
    </div>
    @*<div class="layui-form-item">
        <label class="layui-form-label">是否租赁</label>
        <div class="layui-input-inline">
            <input type="checkbox" name="IsRented" lay-skin="switch" lay-text="已租赁|未租赁">
        </div>
    </div>*@
    <div class="layui-form-item" style="text-align:center;">
        <button class="layui-btn" lay-submit lay-filter="save">保存</button>
        <button class="layui-btn" id="cancel">取消</button>
    </div>
</form>
<script type="text/javascript">
    layui.use(['form', 'jquery'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var parkList = @Html.Raw(ViewBag.ParkList);
        var storehouseList = @Html.Raw(ViewBag.StorehouseList);
        $(parkList).each(function (index, item) {
            $("#ParkID").append("<option value='" + item.ID + "'>" + item.Code + "</option>");
        });
        form.render("select");
        form.on('select(ParkID)', function (data) {
            $("#StorehouseID").empty();
            $(storehouseList).each(function (index, item) {
                if (data.value == item.ParkID) {
                    $("#StorehouseID").append("<option value='" + item.ID + "'>" + item.Code + "</option>");
                }
            });
            form.render("select");
        });
        form.on("submit(save)", function (formdata) {
            //formdata.field.IsRented = formdata.field.IsRented == "on" ? true : false;
            $.ajax({
                url: 'Add',
                data: formdata.field,
                success: function (res) {
                    layer.alert(res.msg, function (index) {
                        layer.close(index);
                        if (res.count > 0) {
                            parent.layer.closeAll();
                        }
                    })
                }
            });
            return false;
        })
        $("#cancel").click(function () {
            parent.layer.closeAll();
        })
    })
</script>